package edu.uclmgmu.bacteriosec.gui;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.AdjustmentEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Vector;

import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JEditorPane;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JRadioButton;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;
import javax.swing.filechooser.FileNameExtensionFilter;

import edu.uclmgmu.bacteriosec.domain.Controller;
import edu.uclmgmu.bacteriosec.domain.Filtro;
import edu.uclmgmu.bacteriosec.domain.data.ListOfAspectsFamilies;

public class JFBacterioSecMain extends JFrame {
	private JPanel contentPane;
	private JTextField tfAspectedOperatorsPath;
	private JTextField tfWorkingPath;
	private JTextField tfMainClass;
	private JButton btnAspectsPath;
	private JButton btnMainClass;
	private JButton btnClasspath;
	private JTextField tfClassPath;
	private JButton btnWorkingPath;
	private JEditorPane epLog;
	private JButton btnJunitTestFile;
	private JTextField tfJUnitFile;
	private JButton btnJunitJARPath;
	private JTextField tfJUnitJARPath;
	private JTextField tfAspectsJWeaver;
	private JTextField tfAspectJRT;
	private JTextField tfBootPath;

	private JLabel lblMatches;
	private JLabel lblTime;
	private JLabel lblExecutions;
	private JRadioButton rdbtnExecuteOriginal;
	private JRadioButton rdbtnMakeATrace;
	private JRadioButton rdbtnFullExecution;
	private JRadioButton rdbtnOnlyCountCalls;
	private JCheckBox chckbxOnJunit;
	private JLabel lblProbability;
	private JLabel lblTimeout;
	private JScrollBar scrollBarProbability;

	public final static int ONLY_COUNT = 1;
	public final static int ONLY_ORIGINAL = 2;
	public final static int FULL = 3;
	public final static int MAKE_TRACE = 4;

	private JProgressBar progressBarTask;
	private JProgressBar progressBarActivity;
	private String resultsPath;
	private JDExecutionResults jdExecutionResults;
	private Controller controller;
	private DefaultListModel modelolistMatchedJoinPoints;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					JFBacterioSecMain frame = new JFBacterioSecMain();
					frame.scrollBarProbability.setValue(100);
					frame.updateProbability();
					//frame.loadAspectsTree();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	protected void loadAspectsTree() {
		if (this.tfAspectedOperatorsPath.getText() == null
				|| this.tfAspectedOperatorsPath.getText().length() == 0) {
			return;
		}
		String aspectedOperatorsPath = this.tfAspectedOperatorsPath.getText();
		Filtro f = new Filtro();
		Vector<String> bytesStreamFiles = f.loadFiles(aspectedOperatorsPath, ".class");
		DefaultListModel modelo = new DefaultListModel();
		this.listMatchedJoinPoints.setModel(modelo);
		for (int i = bytesStreamFiles.size() - 1; i >= 0; i--) {
			String byteStreamFile = bytesStreamFiles.get(i);
			if (byteStreamFile.indexOf("$") == -1
					&& !byteStreamFile.endsWith("CountCalls.class")
					&& !byteStreamFile.endsWith("Store.class")
					&& !byteStreamFile.endsWith("GenericTracer.class"))
				modelo.addElement(byteStreamFile);
		}
	}

	/**
	 * Create the frame.
	 */
	public JFBacterioSecMain() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 1286, 842);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(null);
		setContentPane(contentPane);

		tfAspectedOperatorsPath = new JTextField();
		tfAspectedOperatorsPath
				.setText("/Users/Maco/Documents/workspaceJEE/TestAspects/bin");
		tfAspectedOperatorsPath.setBounds(221, 19, 554, 28);
		contentPane.add(tfAspectedOperatorsPath);
		tfAspectedOperatorsPath.setColumns(10);

		tfWorkingPath = new JTextField();
		tfWorkingPath
				.setText("/Users/Maco/Documents/workspaceJEE/PasswordsServer/bin");
		tfWorkingPath.setBounds(130, 134, 645, 28);
		contentPane.add(tfWorkingPath);
		tfWorkingPath.setColumns(10);

		tfMainClass = new JTextField();
		tfMainClass.setText("sut.Lanzadora");
		tfMainClass.setBounds(132, 168, 643, 28);
		contentPane.add(tfMainClass);
		tfMainClass.setColumns(10);

		btnAspectsPath = new JButton("Aspected-operators path");
		btnAspectsPath.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				setAspectsPath();
			}
		});
		btnAspectsPath.setBounds(6, 20, 203, 29);
		contentPane.add(btnAspectsPath);

		btnMainClass = new JButton("Main class");
		btnMainClass.setBounds(6, 168, 117, 29);
		btnMainClass.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				setMainClass();
			}
		});
		contentPane.add(btnMainClass);

		btnClasspath = new JButton("Classpath");
		btnClasspath.setBounds(6, 261, 117, 29);
		contentPane.add(btnClasspath);

		tfClassPath = new JTextField();
		tfClassPath
				.setText("/Users/Maco/Documents/workspaceJEE/ajedrez6_server_bin/mysql-connector-java-5.0.8-bin.jar:/Users/Maco/Documents/workspaceJEE/AspectosMut2/listener.jar");
		tfClassPath.setBounds(132, 260, 643, 28);
		contentPane.add(tfClassPath);
		tfClassPath.setColumns(10);

		btnWorkingPath = new JButton("Working path");
		btnWorkingPath.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				setWorkingPath();
			}
		});
		btnWorkingPath.setBounds(6, 135, 117, 29);
		contentPane.add(btnWorkingPath);

		JScrollPane scrollPaneLog = new JScrollPane();
		scrollPaneLog.setBounds(16, 386, 1253, 428);
		contentPane.add(scrollPaneLog);

		epLog = new JEditorPane();
		epLog.setFont(new Font("Courier", Font.PLAIN, 12));
		scrollPaneLog.setViewportView(epLog);

		btnJunitTestFile = new JButton("JUnit test file");
		btnJunitTestFile.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				setJUnitTestFile();
			}
		});
		btnJunitTestFile.setBounds(6, 199, 117, 29);
		contentPane.add(btnJunitTestFile);

		tfJUnitFile = new JTextField();
		tfJUnitFile.setText("pwdserver.tests.TestServer");
		tfJUnitFile.setBounds(132, 198, 643, 28);
		contentPane.add(tfJUnitFile);
		tfJUnitFile.setColumns(10);

		btnJunitJARPath = new JButton("junit.jar path");
		btnJunitJARPath.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				setJUnitJARPath();
			}
		});
		btnJunitJARPath.setBounds(6, 232, 117, 29);
		contentPane.add(btnJunitJARPath);

		tfJUnitJARPath = new JTextField();
		tfJUnitJARPath
				.setText("/Applications/eclipseJEE/plugins/org.junit_4.10.0.v4_10_0_v20120426-0900/junit.jar:/Applications/eclipseJEE/plugins/org.hamcrest.core_1.1.0.v20090501071000.jar");
		tfJUnitJARPath.setBounds(132, 230, 643, 28);
		contentPane.add(tfJUnitJARPath);
		tfJUnitJARPath.setColumns(10);

		JButton btnAspectsJWeaver = new JButton("aspectjweaver.jar");
		btnAspectsJWeaver.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				setAspectsJWeaver();
			}
		});
		btnAspectsJWeaver.setBounds(6, 47, 203, 29);
		contentPane.add(btnAspectsJWeaver);

		tfAspectsJWeaver = new JTextField();
		tfAspectsJWeaver
				.setText("/Users/Maco/Downloads/aspectj-1.7.2/lib/aspectjweaver.jar");
		tfAspectsJWeaver.setBounds(221, 46, 554, 28);
		contentPane.add(tfAspectsJWeaver);
		tfAspectsJWeaver.setColumns(10);

		JButton btnAspectjJRTPath = new JButton("aspectjrt.jar");
		btnAspectjJRTPath.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				setAspectjJRTPath();
			}
		});
		btnAspectjJRTPath.setBounds(6, 75, 203, 28);
		contentPane.add(btnAspectjJRTPath);

		tfAspectJRT = new JTextField();
		tfAspectJRT
				.setText("/Users/Maco/Downloads/aspectj-1.7.2/lib/aspectjrt.jar");
		tfAspectJRT.setBounds(221, 74, 554, 28);
		contentPane.add(tfAspectJRT);
		tfAspectJRT.setColumns(10);

		JButton btnBootPath = new JButton("Boot path");
		btnBootPath.setBounds(6, 104, 117, 29);
		contentPane.add(btnBootPath);

		tfBootPath = new JTextField();
		tfBootPath
				.setText("/Users/Maco/Documents/workspaceJEE/TestAspects/boot:/Users/Maco/Downloads/commons-logging-1.1.3/commons-logging-1.1.3.jar");
		tfBootPath.setBounds(131, 103, 643, 28);
		contentPane.add(tfBootPath);
		tfBootPath.setColumns(10);

		lblMatches = new JLabel("");
		lblMatches.setBounds(16, 358, 297, 16);
		contentPane.add(lblMatches);

		lblTime = new JLabel("");
		lblTime.setBounds(345, 358, 394, 16);
		contentPane.add(lblTime);

		lblExecutions = new JLabel("");
		lblExecutions.setBounds(751, 358, 168, 16);
		contentPane.add(lblExecutions);

		ButtonGroup executionOptions = new ButtonGroup();

		JPanel panelExecutionOptions = new JPanel();
		panelExecutionOptions.setBorder(new LineBorder(new Color(0, 0, 0)));
		panelExecutionOptions.setBounds(790, 17, 185, 273);
		panelExecutionOptions.setLayout(null);
		contentPane.add(panelExecutionOptions);

		JButton btnExecute = new JButton("Execute");
		btnExecute.setBounds(6, 226, 117, 29);
		panelExecutionOptions.add(btnExecute);

		chckbxOnJunit = new JCheckBox("On JUnit");
		chckbxOnJunit.setSelected(true);
		chckbxOnJunit.setBounds(6, 120, 128, 23);
		panelExecutionOptions.add(chckbxOnJunit);

		rdbtnExecuteOriginal = new JRadioButton("Execute original");
		rdbtnExecuteOriginal.setBounds(6, 86, 141, 23);
		panelExecutionOptions.add(rdbtnExecuteOriginal);

		executionOptions.add(this.rdbtnExecuteOriginal);

		rdbtnFullExecution = new JRadioButton("Full execution");
		rdbtnFullExecution.setBounds(6, 62, 141, 23);
		panelExecutionOptions.add(rdbtnFullExecution);
		executionOptions.add(this.rdbtnFullExecution);

		rdbtnOnlyCountCalls = new JRadioButton("Only count calls");
		rdbtnOnlyCountCalls.setBounds(6, 36, 141, 23);
		panelExecutionOptions.add(rdbtnOnlyCountCalls);
		rdbtnOnlyCountCalls.setSelected(true);
		executionOptions.add(this.rdbtnOnlyCountCalls);

		rdbtnMakeATrace = new JRadioButton("Make a trace");
		rdbtnMakeATrace.setBounds(6, 11, 141, 23);
		panelExecutionOptions.add(rdbtnMakeATrace);
		executionOptions.add(this.rdbtnMakeATrace);

		JLabel lblNewLabel = new JLabel("Probability");
		lblNewLabel.setBounds(6, 155, 93, 20);
		panelExecutionOptions.add(lblNewLabel);

		lblProbability = new JLabel("");
		lblProbability.setBounds(16, 198, 61, 16);
		panelExecutionOptions.add(lblProbability);

		lblTimeout = new JLabel("");
		lblTimeout.setBounds(16, 251, 162, 16);
		panelExecutionOptions.add(lblTimeout);

		scrollBarProbability = new JScrollBar();
		scrollBarProbability.setValue(100);
		scrollBarProbability.addAdjustmentListener(new AdjustmentListener() {
			public void adjustmentValueChanged(AdjustmentEvent arg0) {
				updateProbability();
			}
		});
		scrollBarProbability.setMaximum(110);
		scrollBarProbability.setMinimum(1);
		scrollBarProbability.setOrientation(JScrollBar.HORIZONTAL);
		scrollBarProbability.setBounds(6, 183, 162, 20);
		panelExecutionOptions.add(scrollBarProbability);

		progressBarTask = new JProgressBar();
		progressBarTask.setBounds(166, 326, 1103, 20);
		contentPane.add(progressBarTask);

		progressBarActivity = new JProgressBar();
		progressBarActivity.setBounds(166, 294, 1103, 20);
		contentPane.add(progressBarActivity);

		lblCurrentActivity = new JLabel("");
		lblCurrentActivity.setBounds(16, 298, 138, 16);
		contentPane.add(lblCurrentActivity);

		lblCurrentTask = new JLabel("");
		lblCurrentTask.setBounds(16, 326, 138, 16);
		contentPane.add(lblCurrentTask);

		JScrollPane scrollPane = new JScrollPane();
		scrollPane.setBounds(988, 46, 280, 158);
		contentPane.add(scrollPane);

		listMatchedJoinPoints = new JList();
		listMatchedJoinPoints.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				if (e.getClickCount()==2)
					removeJoinPoint();
			}
		});
		scrollPane.setViewportView(listMatchedJoinPoints);

		JLabel lblNewLabel_1 = new JLabel("Matched join points:");
		lblNewLabel_1.setBounds(987, 19, 168, 16);
		contentPane.add(lblNewLabel_1);

		btnExecute.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent arg0) {
				executeAccordingToOptions();
			}
		});
		this.controller = new Controller(this);
		this.modelolistMatchedJoinPoints=new DefaultListModel();
		this.listMatchedJoinPoints.setModel(this.modelolistMatchedJoinPoints);
		
		btnContinue = new JButton("Continue");
		btnContinue.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				controller.continueFullExecution();
			}
		});
		btnContinue.setBounds(1154, 203, 117, 29);
		contentPane.add(btnContinue);
		
		JButton btnRemoveSelected = new JButton("Remove selected");
		btnRemoveSelected.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				removeSelectedJoinPoints();
			}
		});
		btnRemoveSelected.setBounds(986, 204, 153, 29);
		contentPane.add(btnRemoveSelected);
		
		JPanel panelVerbose = new JPanel();
		panelVerbose.setBounds(984, 233, 285, 56);
		panelVerbose.setLayout(null);
		contentPane.add(panelVerbose);
		
		lblVerbosity = new JLabel("Verbosity");
		lblVerbosity.setBounds(6, 6, 61, 16);
		panelVerbose.add(lblVerbosity);
		
		rdbtnAllegro = new JRadioButton("Allegro");
		rdbtnAllegro.setBounds(6, 27, 77, 23);
		panelVerbose.add(rdbtnAllegro);
		
		ButtonGroup grupoVerbosity=new ButtonGroup();
		rdbtnAllegroMaNonTroppo = new JRadioButton("Allegro ma non troppo");
		rdbtnAllegroMaNonTroppo.setSelected(true);
		rdbtnAllegroMaNonTroppo.setBounds(85, 27, 194, 23);
		grupoVerbosity.add(rdbtnAllegro);
		grupoVerbosity.add(rdbtnAllegroMaNonTroppo);
		panelVerbose.add(rdbtnAllegroMaNonTroppo);
	}

	protected void removeSelectedJoinPoints() {
		int index=this.listMatchedJoinPoints.getSelectedIndex();
		if (index==-1)
			return;
		Object[] selectedJPs= this.listMatchedJoinPoints.getSelectedValues();
		for (int i=0; i<selectedJPs.length; i++) {
			String jpName=selectedJPs[i].toString();
			this.modelolistMatchedJoinPoints.removeElement(jpName);
			this.controller.removeMatchedJoinPoint(jpName);			
		}
	}

	protected void removeJoinPoint() {
		int index=this.listMatchedJoinPoints.getSelectedIndex();
		if (index==-1)
			return;
		String jpName=this.modelolistMatchedJoinPoints.get(index).toString();
		this.modelolistMatchedJoinPoints.remove(index);
		this.controller.removeMatchedJoinPoint(jpName);
	}

	protected void executeAccordingToOptions() {
		this.modelolistMatchedJoinPoints.clear();
		this.controller.setProbability(this.scrollBarProbability.getValue());
		this.controller.setExecuteOnJUnit(this.chckbxOnJunit.isSelected());
		this.controller.setWorkingPath(this.tfWorkingPath.getText());
		this.controller.setAspectedOperatorsPath(this.tfAspectedOperatorsPath.getText());
		this.controller.setAspectJRT(this.tfAspectJRT.getText());
		this.controller.setClassPath(this.tfClassPath.getText());
		this.controller.setJUnitJarPath(this.tfJUnitJARPath.getText());
		this.controller.setJUnitFile(this.tfJUnitFile.getText());
		this.controller.setMainClass(this.tfMainClass.getText());
		this.controller.setBootPath(this.tfBootPath.getText());
		this.controller.setAspectJWeaver(this.tfAspectsJWeaver.getText());
		int verbosityLevel;
		if (this.rdbtnAllegro.isSelected())
			verbosityLevel=Controller.ALLEGRO;
		else
			verbosityLevel=Controller.ALLEGRO_MA_NON_TROPPO;
		this.controller.setVerbosityLevel(verbosityLevel);
		this.controller.run();
	}

	protected void updateProbability() {
		if (this.scrollBarProbability.getValue() < 0
				|| this.scrollBarProbability.getValue() > 100)
			return;
		this.lblProbability.setText(this.scrollBarProbability.getValue() + "%");
	}

	protected void setAspectjJRTPath() {
		selectJARFile(this.tfAspectJRT);
	}

	private String selectJARFile(JTextField textField) {
		String currentDirectory = textField.getText();
		JFileChooser jd = new JFileChooser(currentDirectory);
		FileNameExtensionFilter filter = new FileNameExtensionFilter(
				"JAR files", "jar");
		jd.setFileFilter(filter);
		jd.setFileSelectionMode(JFileChooser.FILES_ONLY);
		int returnVal = jd.showOpenDialog(this);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			String className = jd.getSelectedFile().getAbsolutePath();
			textField.setText(className);
			return className;
		}
		return null;
	}

	private String selectClassFile(JTextField textField) {
		String currentDirectory = this.tfWorkingPath.getText();
		JFileChooser jd = new JFileChooser(currentDirectory);
		FileNameExtensionFilter filter = new FileNameExtensionFilter(
				"Class files", "class");
		jd.setFileFilter(filter);
		jd.setFileSelectionMode(JFileChooser.FILES_ONLY);
		int returnVal = jd.showOpenDialog(this);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			String className = jd.getSelectedFile().getAbsolutePath();
			if (currentDirectory.length() + 1 < className.length()) {
				className = className.substring(currentDirectory.length() + 1);
				String auxi = "";
				for (int i = 0; i < className.length(); i++)
					auxi += (className.charAt(i) == '/' ? '.' : className
							.charAt(i));
				className = auxi;
			}
			if (className != null && className.endsWith(".class"))
				className = className.substring(0, className.length() - 6);
			textField.setText(className);
			return className;
		}
		return null;
	}

	protected void setAspectsJWeaver() {
		selectJARFile(this.tfAspectsJWeaver);
	}

	protected void setJUnitTestFile() {
		String className = selectClassFile(this.tfJUnitFile);
		this.tfJUnitFile.setText(className);
	}

	protected void setJUnitJARPath() {
		selectJARFile(this.tfJUnitJARPath);
	}

	private int currentTask;
	private JLabel lblCurrentActivity;
	private JLabel lblCurrentTask;
	private JList listMatchedJoinPoints;

	public void updateProgressBarTask() {
		this.progressBarTask.setValue(++currentTask);
	}

	public void setNumberOfTasks(int max) {
		this.progressBarTask.setValue(0);
		this.progressBarTask.setMaximum(max);
	}

	public void log(ListOfAspectsFamilies aspectsFamiliesUsed) {
		if (this.jdExecutionResults == null) {
			this.jdExecutionResults = new JDExecutionResults();
		}
		this.jdExecutionResults.setTempPath(this.resultsPath);
		//this.jdExecutionResults.setResults(aspectsFamiliesUsed);
		this.jdExecutionResults.loadResults(this.resultsPath, aspectsFamiliesUsed);
		this.jdExecutionResults.setVisible(true);
	}

	public void log(String byteStreamFile, int rt, String salida) {
		salida = salida.replaceAll("<br>", "\n\t");
		String msj;
		if (byteStreamFile.length() == 0 || byteStreamFile.indexOf("CountCalls") != -1) {
			msj = "Start execution of original\n";
		} else {
			msj = "\t\t\t\tStart execution of " + byteStreamFile + "\n";
		}
		msj += "\t\t\t\t\tReturn value = " + rt + "\n";
		msj += "\t\t\t\t\tOutput:\n";
		if (this.rdbtnAllegroMaNonTroppo.isSelected()) {
			msj+="\t\t\t\t\t\t" + salida + "\n";
		} else {
			msj += salida;
		}
		msj = this.epLog.getText() + msj;

		if (byteStreamFile.length() == 0 || byteStreamFile.indexOf("CountCalls") != -1) {
			msj += "End execution of original\n";
		} else {
			msj += "\t\t\t\tEnd execution of " + byteStreamFile + "\n";
		}
		this.epLog.setText(msj);
	}

	int kkk = 1;
	private JButton btnContinue;
	private JLabel lblVerbosity;
	private JRadioButton rdbtnAllegro;
	private JRadioButton rdbtnAllegroMaNonTroppo;

	private void save(String fileName, String text) {
		try {
			FileOutputStream fos = new FileOutputStream(this.resultsPath
					+ fileName);
			fos.write(text.getBytes());
			fos.close();
		} catch (Exception e) {
			log("Error saving file " + text + ": " + e.toString());
		}
	}

	public void log(String msg) {
		msg = msg.replaceAll("<br\\/>", "\n");
		String msj = msg + "\n";
		msj = this.epLog.getText() + msj;
		this.epLog.setText(msj);
	}

	protected void setWorkingPath() {
		String currentDirectory = this.tfWorkingPath.getText();
		JFileChooser jd = new JFileChooser(currentDirectory);
		jd.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		int returnVal = jd.showOpenDialog(this);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			this.tfWorkingPath.setText(jd.getSelectedFile().getAbsolutePath());
		}
	}

	protected void setMainClass() {
		selectClassFile(this.tfMainClass);
	}

	protected void setAspectsPath() {
		String currentDirectory = this.tfAspectedOperatorsPath.getText();
		JFileChooser jd = new JFileChooser(currentDirectory);
		jd.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		int returnVal = jd.showOpenDialog(this);
		if (returnVal == JFileChooser.APPROVE_OPTION) {
			this.tfAspectedOperatorsPath.setText(jd.getSelectedFile()
					.getAbsolutePath());
			this.loadAspectsTree();
		}
	}

	public static void copyFile(String source, String target)
			throws IOException {
		FileInputStream fi = new FileInputStream(source);
		byte[] b = new byte[fi.available()];
		fi.read(b);
		fi.close();
		FileOutputStream fos = new FileOutputStream(target);
		fos.write(b);
		fos.close();
	}

	public void setCurrentActivity(int value) {
		this.progressBarActivity.setValue(value);
	}

	public void setNumberOfActivities(int max) {
		progressBarActivity.setValue(0);
		progressBarActivity.setMaximum(max);
	}

	public boolean getExecuteOnJunit() {
		return chckbxOnJunit.isSelected();
	}

	public boolean getOnlyCountCalls() {
		return rdbtnOnlyCountCalls.isSelected();
	}

	public void setCurrentActivityText(String text) {
		lblCurrentActivity.setText(text);
	}

	public boolean getFullExecution() {
		return rdbtnFullExecution.isSelected();
	}

	public void setCurrentTaskText(String text) {
		lblCurrentTask.setText(text);
	}

	public void setCurrentTask(int value) {
		progressBarTask.setValue(value);
	}

	public boolean getMakeATrace() {
		return rdbtnMakeATrace.isSelected();
	}

	public boolean getExecuteOriginal() {
		return rdbtnExecuteOriginal.isSelected();
	}

	public void setTimeoutText(String text) {
		this.lblTimeout.setText(text);
	}

	public void setMatchesText(String text) {
		this.lblMatches.setText(text);
	}

	public void setTimeText(String text) {
		this.lblTime.setText(text);
	}

	public String getAspectedOperatorsPath() {
		return this.tfAspectedOperatorsPath.getText();
	}

	public String getWorkingPath() {
		return this.tfWorkingPath.getText();
	}

	public String getAspectJRT() {
		return this.tfAspectJRT.getText();
	}

	public String getJUnitJARPath() {
		return this.tfJUnitJARPath.getText();
	}

	public String getClassPath() {
		return this.tfClassPath.getText();
	}

	public String getJUnitFile() {
		return this.tfJUnitFile.getText();
	}

	public String getMainClass() {
		return this.tfMainClass.getText();
	}

	public String getAspectJWeaver() {
		return this.tfAspectsJWeaver.getText();
	}

	public String getBootPath() {
		return this.tfBootPath.getText();
	}

	public int getProbability() {
		return this.scrollBarProbability.getValue();
	}

	public void setNumberOfExecutionsText(String text) {
		this.lblExecutions.setText(text);
	}

	public void setResultsPath(String resultsPath) {
		this.resultsPath=resultsPath;
	}

	public void addUsedJoinPoint(String jpName) {
		modelolistMatchedJoinPoints.addElement(jpName.substring(jpName.lastIndexOf("/")+1));
	}
}
